//=============================================================================
// Sentinel Hit Effect - Handles spawning of different effects on different surfaces.
//=============================================================================
class WoEHitEffect extends Actor;

#exec OBJ LOAD FILE=VMParticleTextures.utx
#exec OBJ LOAD FILE=VehicleFX.utx
#exec OBJ LOAD FILE=XGameShadersB.utx
#exec OBJ LOAD FILE=EmitterTextures.utx

var() class<WoEHitEmitter> HitEffectClasses[11]; //Effects indexed by surface type.
var() class<WoEBulletDecal> DecalClasses[11];

static function StaticPrecache(LevelInfo L)
{
	L.AddPrecacheMaterial(Texture'VMParticleTextures.DirtKICKGROUP.dirtKICKTEX');
	L.AddPrecacheMaterial(Texture'VMParticleTextures.DirtKICKGROUP.snowKICKTEX');
	L.AddPrecacheMaterial(Texture'VehicleFX.Particles.DustyCloud2');
	L.AddPrecacheMaterial(Texture'XGameShadersB.Blood.BloodJetc');
	L.AddPrecacheMaterial(Texture'AW-2004Particles.Energy.SparkHead');
	L.AddPrecacheMaterial(Texture'XEffects.EmitSmoke_t');
	L.AddPrecacheMaterial(Texture'EmitterTextures.MultiFrame.rockchunks02');
	L.AddPrecacheMaterial(Texture'EmitterTextures.MultiFrame.MistTexture');
}

simulated function PostBeginPlay()
{
	SpawnEffects();
}

simulated function SpawnEffects()
{
	local Material SurfaceMat;
	local int HitSurface;
	local Vector HitLocation, HitNormal;
	local rotator EffectDir;
	local Actor Other;

	Other = Trace(HitLocation, HitNormal, Location + vector(Rotation) * 32, Location - vector(Rotation) * 16, true,, SurfaceMat);

	EffectDir = rotator(MirrorVectorByNormal(vector(Rotation), HitNormal));

	if(Vehicle(Other) != None && Other.SurfaceType == 0) //Hack to make vehicles behave like metal.
		HitSurface = 3;
	else if(Other != None && !Other.IsA('LevelInfo') && Other.SurfaceType != 0)
		HitSurface = Other.SurfaceType;
	else if(SurfaceMat != None)
		HitSurface = SurfaceMat.SurfaceType;
	else //No surface? Arghhh!!!!
	{
		Destroy();
		return;
	}

	if(PhysicsVolume.bWaterVolume)
		Spawn(class'pclImpactSmoke');
	else
		Spawn(HitEffectClasses[HitSurface],,,, EffectDir);

	if(Other != None && Other.bWorldGeometry && DecalClasses[HitSurface] != None)
		Spawn(DecalClasses[HitSurface]);

	Destroy();
}

defaultproperties
{
     bHidden=True
     LifeSpan=5.000000
}
